
happign for foresters
Source:vignettes/web_only/happign_for_foresters.Rmd
happign_for_foresters.Rmd
library(happign)
library(sf)
library(tmap); tmap_mode("view") # Set map to interactive
library(dplyr)
library(ggplot2)
library(purrr)First choose a zone of interest
For the example we will work with the Gâvre forest. The starting point come from google map : you just have to select a random point inside the forest by using right click on map.
Extract commune borders
Now that we have point, getting shape of commune is just a matter of finding the good layer name from IGN. The one we are after is called “ADMINEXPRESS-COG-CARTO.LATEST:commune” from the “Administrative” category. Then we use the get_wfs() function to download the shape.
As you can see below, there are two communes close to our point (tip : click on the interactive map below to get more info). For following examples we will only use “Le Gâvre” shape.
apikey <- get_apikeys()[1] # "administratif"
layer_name <- "ADMINEXPRESS-COG-CARTO.LATEST:commune"
# The layer_name I use come from `all_layers = get_layers_metadata(apikey, "wfs") that return all of them layer_name
borders <- get_wfs(shape = point,
apikey = apikey,
layer_name = layer_name)
#> 1/1 downloaded
tm_shape(borders)+
tm_polygons(lwd = 2,
col = "nom",
id = "nom",
popup.vars = "population")+
tm_basemap("OpenStreetMap")Download cadastral parcel
Cadastral parcels are essential for any forest management. Here how to download it with happign.
# Select only commune to reduce downloading time for hight resolution raster
borders <- borders %>%
slice(1)
apikey <- get_apikeys()[14] # "parcellaire"
layer_name <- get_layers_metadata(apikey, "wfs")
name_parcellaire_layer <- as.character(layer_name[15,2]) # "CADASTRALPARCELS.PARCELLAIRE_EXPRESS:parcelle"
parcellaire <- get_wfs(shape = borders,
apikey = apikey,
layer_name = name_parcellaire_layer) %>%
st_transform(st_crs(borders)) %>%
st_intersection(borders)
#> 1/10 downloaded
#> 2/10 downloaded
#> 3/10 downloaded
#> 4/10 downloaded
#> 5/10 downloaded
#> 6/10 downloaded
#> 7/10 downloaded
#> 8/10 downloaded
#> 9/10 downloaded
#> 10/10 downloaded
#> Warning: attribute variables are assumed to be spatially constant throughout all
#> geometries
tm_shape(borders)+
tm_borders(col = "red", lwd = 2)+
tm_shape(parcellaire)+
tm_polygons(alpha = 0)+
tm_basemap("OpenStreetMap")